//
//  PhotoBrowerView.m
//  Safflower
//
//  Created by 袁亮 on 2017/1/3.
//  Copyright © 2017年 SpaceZ. All rights reserved.
//

#import "PhotoBrowerView.h"

@interface PhotoBrowerView()

@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation PhotoBrowerView

+ (PhotoBrowerView *)sharedBrower
{
    static PhotoBrowerView *brower = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        brower = [[self alloc] init];
    });
    return brower;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = RGBA(0, 0, 0, 0.5);
        
        [self makeImageView];
    }
    return self;
}

- (void)makeImageView
{
    _imageView = [UIImageView new];
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:_imageView];
}

- (void)showBrower:(SignModel *)signBrower
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(0);
    }];
    
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(40);
        make.right.mas_equalTo(-40);
    }];
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseIp,signBrower.image]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (error == nil) {
            
        }
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self removeFromSuperview];
}

@end
